package mapper_1;

import jdk.jfr.Category;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import pojo.Music;

import java.util.List;

//2420710103_刘小文

public interface MusicMapper {
//    public List<Music> findAll();

    @Select("select * from tb_music")
    public List<Music> findAll();

    //2420710103_刘小文 三、根据音乐ID查询音乐及所关联的类别信息。
    @Select("select * from tb_music m where m.id = #{id}")
         @Results({
                 @Result(id = true,column = "id",property = "id"),
                 @Result(column = "musicname",property = "musicname"),
                 @Result(column = "singer",property = "singer"),
                 @Result(column = "ranking",property = "ranking"),
                 @Result(column = "category_id",property = "category_id"),
                 @Result(
                         property = "category",
                         column = "category_id",
                         javaType = Category.class,
                        one = @One(select = "mapper_1.CategoryMapper.findCategoryById")
                 )
         })
//    需要传入我们的音乐的id
    public List<Music> findMusicCatByid(int id);


//    根据我们的 category_id 查询我们的音乐
    @Select("select  * from tb_music where category_id = #{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "musicname",property = "musicname"),
            @Result(column = "singer",property = "singer"),
            @Result(column = "ranking",property = "ranking"),
            @Result(column = "category_id",property = "category_id")
    })
    public List<Music> findMusicByc_id(int id);
}

